- Read the entries of an array of 5 integers from a user. Next, loop through the array and print the odd numbers and then print the even numbers. Finally, print the sum of all the numbers entered.
Sample run of program:
Enter five numbers: 3 1 6 9 2
3 1 9
6 2
Sum of all numbers: 21
- Initialize an integer array of size 10 with random numbers between 1 and 20 (inclusive). Print the array, then loop through the array adding 2 to every number. Print the updated array.
Sample run of program:
19 13 12 18 14 3 13 10 9 10
21 15 14 20 16 5 15 12 11 12
- Initialize an integer array of size 50 to random numbers between 1 and 100 (inclusive). Print the array, then find the (a) smallest number in the array and (b) the largest number in that array and print both to the monitor.
Sample run of program:
38 53 59 54 36 5 99 18 29 74
The largest number in the array is 99
The smallest number in the array is 5
- Read the entries of an array of 10 integers from a user. Compute x as the average of the 10 entries. Output this to the monitor. Next, compute the average of those array entries with values greater than or equal to x. Print this second, final average to the monitor.
Sample run of program:
Enter ten numbers: 12 9 34 22 6 45 76 2 34 19
Average of entries in array: 25.9
Average of entries greater than overall average: 47.25
- Write a program in which you declare a string array of size 3 and an integer array of size 3. Initialize the string array to {"[Your name]", "Alice", "Bob"}. Initialize the integer array to {100, 90, 80}. Using a for loop, print the following:
[Your name]'s score is 100.
Alice's score is 90.
Bob's score is 80.
HINT: Notice that "[Your name]" and 100 are each at index position 0 in the respective arrays. "Alice" and 90 are at index position 1 in the respective arrays, and "Bob" and 80 are at index position 2 in the respective arrays. Leverage these facts when printing out the requested statements.